package com.woniuxy.advice;

import com.woniuxy.config.RedisConfig;
import com.woniuxy.param.UserLoginParam;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MyAdviceConfig {
    @Autowired
    private RedisConfig redisConfig;

    @After("@annotation(com.woniuxy.annotation.DayOrderRecord)")
    public void dayOrderRecord(){
//        Object[] args = joinPoint.getArgs();
//        Order order = (Order) args[0];
        if(null==redisConfig.opsForValue().get("DayOrderRecord")){
            redisConfig.opsForValue().set("DayOrderRecord","1");
        }else{
            Integer value = Integer.parseInt((String) redisConfig.opsForValue().get("DayOrderRecord"));
            redisConfig.opsForValue().set("DayOrderRecord",String.valueOf(value+1));
        }
    }
    @After("@annotation(com.woniuxy.annotation.PersonRecord)")
    public void PersonRecord(JoinPoint joinPoint){
        //建立person每日统计表redis tel为key,对象为 user
        Object[] args = joinPoint.getArgs();
        UserLoginParam userLoginParam = (UserLoginParam) args[0];
        if(!redisConfig.opsForHash().hasKey("PersonDay",userLoginParam.getTel()))
            redisConfig.opsForHash().put("PersonDay",userLoginParam.getTel(),userLoginParam);
    }
}
